# -*- coding: utf-8 -*-
# transform data to svdfeature

fin1 = open("/home/moore/myWorkplace/svdfeature-1.2.2/demo/dataProcess/data/invited_info_train_purified.txt")
fin2 = open("/home/moore/myWorkplace/svdfeature-1.2.2/demo/dataProcess/data/test_nolabel.txt")
fout1 = open("/home/moore/myWorkplace/svdfeature-1.2.2/demo/binaryClassification/ua.base.example.purified.new", "w")
fout2 = open("/home/moore/myWorkplace/svdfeature-1.2.2/demo/binaryClassification/ua.test.example.new", "w")

dic_user = {}
dic_ques = {}

for line in fin1:
	line = line.strip()
	line_list = line.split("\t")
	#0:question 1:user 2:label
	out_line = ""
	out_line = out_line + line_list[2] + " 0 1 1 "
	if line_list[1] not in dic_user:
		dic_user[line_list[1]] = str(len(dic_user))
	out_line = out_line + dic_user[line_list[1]] + ":1 "
	if line_list[0] not in dic_ques: 
		dic_ques[line_list[0]] = str(len(dic_ques))
	out_line = out_line + dic_ques[line_list[0]] + ":1\n"
	fout1.write(out_line)
fin1.close()
print "ques num: ", len(dic_ques)
print "user num: ", len(dic_user)

for line in fin2:
	line = line.strip()
	line_list = line.split(",")
	#0:question 1:user
	out_line = "0 0 1 1 "

	if line_list[1] not in dic_user:
		dic_user[line_list[1]] = str(len(dic_user))
	out_line = out_line + dic_user[line_list[1]] + ":1 "

	if line_list[0] not in dic_ques:
		dic_ques[line_list[0]] = str(len(dic_ques))
	out_line = out_line + dic_ques[line_list[0]] + ":1\n"
	fout2.write(out_line)
fout2.close()
print "ques num: ", len(dic_ques)
print "user num: ", len(dic_user)